import socket

if __name__ == "__main__":
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  #定义socket套接字  tcp
    s.bind(('0.0.0.0',9999))  #绑定服务到9999端口上
    s.listen(5)  #允许等待连接个数
    while True:
        print('waiting for connection...........')
        conn, addr = s.accept()
        ip_addr, port = addr
        print(f"收到客户端的连接，ip地址为{ip_addr}")
        command = input("请输入你要向客户端发送的命令：")
        conn.send(command.encode('utf-8'))
        result = conn.recv(1024).decode('gbk')
        print(result)
        conn.close()